<template>
	<view class="setting-container">
		<view class="box1" @click="goAboutus">
			<view class="">关于我们</view>
			<u-icon class="icon" name="arrow-right" style="margin-top: 10rpx" color="#fff" bold size="13"></u-icon>
		</view>
		<view class="box1" @click="gopolicy">
			<view class="">隐私协议</view>
			<u-icon class="icon" name="arrow-right" style="margin-top: 10rpx" color="#fff" bold size="13"></u-icon>
		</view>
		<view class="box1" @click="gouserrule">
			<view class="">用户协议</view>
			<u-icon class="icon" name="arrow-right" style="margin-top: 10rpx" color="#fff" bold size="13"></u-icon>
		</view>
		<view class="box1" @click="gologout">
			<view class="">注销账号</view>
			<u-icon class="icon" name="arrow-right" style="margin-top: 10rpx" color="#fff" bold size="13"></u-icon>
		</view>
		<view class="box1" @click="updataServion">
			<view class="" style="display: flex">
				<view class="">版本更新</view>
				<view v-if="newVersion == oldVersion" class="" style="margin-left: 100rpx; font-size: 24rpx; margin-top: 5rpx">您当前已是最新版本</view>
				<view v-else class="" style="margin-left: 100rpx; font-size: 24rpx; margin-top: 5rpx">发现新版本{{ newVersion }}请您及时更新</view>
			</view>
			<u-icon class="icon" name="arrow-right" style="margin-top: 10rpx" color="#fff" bold size="13"></u-icon>
		</view>
		<view class="item-box" @click="loginOutShow = true">退出登录</view>
		<!-- 退出登录弹出层 -->
		<u-modal :show="loginOutShow" width="500rpx" :content="loginOutContent" showCancelButton @cancel="loginOutShow = false" @confirm="logOut"></u-modal>
	</view>
</template>

<script>
import { removeToken, removeUserAdmin } from '@/utils/auth.js';
import { toast } from '../../../utils/common';
import { logOff } from '@/api/account/account.js';
import { updateVersion } from '@/api/index.js';
export default {
	data() {
		return {
			newVersion: '',
			oldVersion: '',
			show: false,
			loginOutShow: false, //退出登录弹出层
			loginOutContent: '确定要退出登录吗？'
		};
	},
	created() {
		this.getVer();
	},
	methods: {
		async checkAccount() {
			const data = await logOff();
			if (data.code === 200) {
				this.$modal.msgSuccess('注销成功');
				this.storage.cleanLocalStorage();
			} else {
				this.$modal.msgError(data.msg);
			}
		},
		async getVer() {
			const data = await updateVersion();
			//模拟接口获取最新版本号，版本号固定为整数
			// const newVersionName = 'V1.2.0'; //线上最新版本名
			const newVersionCode = data.data[0].androidVersionNumber; //线上最新版本号
			const selfVersionCode = uni.getSystemInfoSync().appVersion; //当前App版本号

			this.oldVersion = selfVersionCode;
			this.newVersion = newVersionCode;
		},
		async updataServion() {
			const data = await updateVersion();
			// console.log(data, '版本更新');
			//模拟接口获取最新版本号，版本号固定为整数
			// const newVersionName = 'V1.2.0'; //线上最新版本名
			const newVersionCode = data.data[0].androidVersionNumber; //线上最新版本号
			const selfVersionCode = uni.getSystemInfoSync().appVersion; //当前App版本号
			// console.log(newVersionCode, 'App');
			this.newVersion = selfVersionCode;
			//线上版本号高于当前，进行在线升级
			if (selfVersionCode !== newVersionCode) {
				let platform = uni.getSystemInfoSync().platform; //手机平台
				//安卓手机弹窗升级
				// console.log(newVersionCode, 'new');
				// console.log(selfVersionCode, 'old');
				if (platform === 'android') {
					uni.navigateTo({
						url: `/pages/work/upgrade?downUrl=${data.data[0].releaseUrl}&androidUpdateDescription=${data.data[0].androidUpdateDescription}&newVersionCode=${data.data[0].androidVersionNumber}`
					});
				}
				//IOS无法在线升级提示到商店下载
				// else {
				// 	uni.showModal({
				// 		title: '发现新版本 ' + newVersionName,
				// 		content: '请到App store进行升级',
				// 		showCancel: false
				// 	});
				// }
			}
		},

		cancel() {
			this.show = false;
		},
		close() {
			this.show = false;
			// console.log('close');
		},
		// 退出登录
		logOut() {
			removeUserAdmin();
			removeToken();
			toast('退出登录成功');
			setTimeout(function () {
				uni.redirectTo({
					url: '/pages/login'
				});
			}, 700);
		},

		gologout() {
			toast('暂未开放');
		},
		goAboutus() {
			uni.navigateTo({
				url: '/pages/AccountSecurity/setting/about'
			});
		},
		gopolicy() {
			uni.navigateTo({
				url: '/pages/AccountSecurity/setting/policy'
			});
		},
		gouserrule() {
			uni.navigateTo({
				url: '/pages/AccountSecurity/setting/userrule'
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.box1 {
	width: 680rpx;
	height: 110rpx;
	border-bottom: 0.5rpx solid rgba(255, 255, 255, 0.1);
	text-align: center;
	line-height: 70rpx;
	margin: 0 34rpx;
	// background-color: pink;
	display: flex;
	font-size: 28rpx;
	font-family: 'font';
	font-weight: 500;
	color: #ffffff;
	justify-content: space-between;
	padding: 20rpx 30rpx;
}

::v-deep .list-cell {
	background: none;
	padding: 17px 30px;
	color: #ffffff;
}

.menu-item-box {
	font-size: 28rpx;
	font-family: 'font';
	font-weight: 400;
}

.item-box {
	width: 680rpx;
	height: 77rpx;
	background: linear-gradient(90deg, #3ADFEB 0%, #4463FF 100%);
	border-radius: 14rpx;
	margin: 310rpx 34.88rpx;
	font-size: 28rpx;
	font-family: 'font';
	font-weight: 800;
	color: #ffffff;
	text-align: center;
	line-height: 80rpx;
}

::v-deep .list-cell-arrow::before {
	right: 2px;
	border-color: #fff;
	margin-right: 30rpx;
}

.clpmklj {
	display: flex;
	margin: 40rpx 0;

	button:nth-child(2) {
		width: 180rpx;
		height: 78rpx;
		background: linear-gradient(90deg, #3ADFEB 0%, #4463FF 100%);
		border-radius: 16rpx;
		opacity: 1;
		font-size: 31rpx;
		font-family: 'font';
		font-weight: 800;
		color: #ffffff;
	}

	button:nth-child(1) {
		width: 180rpx;
		height: 78rpx;
		background: gray;
		border-radius: 16rpx;
		opacity: 1;
		font-size: 31rpx;
		font-family: 'font';
		font-weight: 800;
		color: #ffffff;
	}
}
</style>